package com.xingkeduo.controller;


import com.alibaba.fastjson.JSONObject;
import com.xingkeduo.dao.workpad.TStaffAttendanceMapper;
import com.xingkeduo.dao.workpad.TStaffStockMapper;
import com.xingkeduo.model.po.TShopsDays;
import com.xingkeduo.model.po.TStaffStock;
import com.xingkeduo.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: 中文输入法发挥不稳定的刘川
 * @Date: 19-3-8 下午9:28
 */
@RestController
public class TestController {

    @Value("${db.mysql.workpad.url}")
    private String a;
    @Autowired
    private TestService testService;
    @Autowired
    private ShopService shopService;
    @Autowired
    private ShopDayService shopDayService;
    @Autowired
    private TStaffStockMapper staffStockMapper;
    @Autowired
    private TStaffAttendanceMapper attendanceMapper;
    @Autowired
    private StaffAttendanceService staffAttendanceService;
    @Autowired
    BusinessuserFeignService businessuserFeignService;


    @RequestMapping("test")
    public List<Long>  hello(){
        List<Long>  m=shopService.getEnableShopIdList();
        TShopsDays shopsDays= shopDayService.getShopDayPlanByShopId(7L,"5");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date=null;
        try {
            date = format.parse("2019-03-18");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Boolean a= staffStockMapper.needToRest(3,date,7L);
        Integer n= staffStockMapper.staffNumInShop(date,7L);
        List<TStaffStock> staffStockList= staffStockMapper.selectEnableStockByDateAndStoreId(date,7L);
        System.out.println(a+n.toString());
        return m;
    }

    @RequestMapping("test2")
    public List<Long>  hello2(Date weekday){
        List<Long>  m=shopService.getEnableShopIdList();
        staffAttendanceService.unableStaffAttendanceByStoreIdAndStaffIdAndWeek(1111l,2019011133279009320L,weekday);


        return m;
    }

    @GetMapping("test3")
    public String test3(@RequestBody List<Long> staffIds, String type){
        List<Long> staffIdList = new ArrayList<>();
        staffIdList.add(22494054901772l);
        staffIdList.add(22499613374476l);
        staffIdList.add(22500858992652l);
        String result = businessuserFeignService.getshop(staffIdList, "1");
        JSONObject jsonObject = JSONObject.parseObject(result);
        String status = jsonObject.get("status").toString();
        //判断服务返回结果
        if("0".equals(status)){
            return "失败";
        }
        String data = jsonObject.get("data").toString();
        return data;
    }

}
